package view;

import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import entities.Crianca;

public class JPanelCrianca extends JPanel implements MouseListener {
	/**
	 * 
	 */
	private static final long serialVersionUID = -635093487909742943L;
	static WindowMain windowMainFrame;
	private ImageIcon estado1 = new ImageIcon(getClass()
			.getClassLoader().getResource("bonecobola1.png"));
	private ImageIcon estado2 = new ImageIcon(getClass()
			.getClassLoader().getResource("bonecobola2.png"));
	private ImageIcon estadoDormindo1 = new ImageIcon(getClass()
			.getClassLoader().getResource("descansando1.png"));
	private ImageIcon estadoDormindo2 = new ImageIcon(getClass()
			.getClassLoader().getResource("descansando2.png"));
	private JLabel kid = new JLabel(estado1);
	private JLabel kid2 = new JLabel(estado2);
	private JLabel kidSleep1 = new JLabel(estadoDormindo1);
	private JLabel kidSleep2 = new JLabel(estadoDormindo2);
	private Crianca crianca;

	public JPanelCrianca(Crianca c) {
		this.setLayout(new FlowLayout());
		this.add(kid);
		this.add(kid2);
		this.add(kidSleep1);
		this.add(kidSleep2);
		
		kid2.setVisible(false);
		if(c.TemBola())
			kidSleep1.setVisible(false);
		else
			kid.setVisible(false);
		kidSleep2.setVisible(false);
		crianca = c;
		this.addMouseListener(this);
		c.setPainel(this);
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		this.setBackground(Color.black);
		this.updateUI();
		windowMainFrame.getjButtonIniciar().setEnabled(true);
		windowMainFrame.setLastClicked(this);
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {

	}

	public JLabel getKid() {
		return kid;
	}

	public void setKid(JLabel kid) {
		this.kid = kid;
	}

	public Crianca getCrianca() {
		return crianca;
	}

	public void setCrianca(Crianca crianca) {
		this.crianca = crianca;
	}

	public void mudarEstadoBrincando(long l) {
		kidSleep1.setVisible(false);
		kidSleep2.setVisible(false);
		if (l % 2 == 0) {
			kid.setVisible(false);
			kid2.setVisible(true);
		}else {
			kid2.setVisible(false);
			kid.setVisible(true);
		}
		this.updateUI();
	}

	public void mudarEstadoDescansando(long l) {
		
		kid2.setVisible(false);
		kid.setVisible(false);
		if (l % 2 == 0) {
			kidSleep1.setVisible(false);
			kidSleep2.setVisible(true);
		}else {
			kidSleep2.setVisible(false);
			kidSleep1.setVisible(true);
		}
		this.updateUI();
	}
}
